<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{log_name} : {log_account_no}</title>
<link rel="shortcut icon" href="{dir_image}favicon.ico">
<link rel="stylesheet" type="text/css" href="{dir_css}Global.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Popup.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Students.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Registrar.css" />

<script type="text/javascript" src="{dir_js}jquery.min.js"></script>
<script type="text/javascript" src="{dir_js}Global.js"></script>

</head>
<body>
<!-- POPUP -->{page_popup}<!-- POPUP END -->
<!-- TOP HEADER -->{page_header}<!-- TOP HEADER END -->
	<div class="main-content">
		{stud_sub_menu}
		<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr valign="top" align="left">
				<td width="300" height="100">
					<div class="semester-menu">
						<div class="semester-menu-label">My Semester</div>
						<div class="semester-menu-listing">{stud_active_sem}</div>
					</div>
				</td>
				<td width="5"></td>
				<td width="665">
					<div class="semester-menu-listing">
						<div class="semester-page">
								
								<div class="div-reg-transfery">
									<ul class="ul-reg-transfery">
										<li class="li-reg-transfery">ONLINE REGISTRATION</li>
									</ul>
								</div>
								<div class="div-reg-pointer" id="click_type_reg_transfer">
									{sem_desc} ({sem_code}) |
									<span id="units_label" style="color:#00F; font-size:14px;">Units : <span id="add_units">0</span>/<span id="total_units">-</span></span>
								</div>
								<form method="post" enctype="multipart/form-data" action="" onsubmit="return validateForm()" >
									<div class="enrollment-popup" id="view_enrollment_popup"><!--  display-none -->
										<table width="0" border="0" cellspacing="0" cellpadding="0">
											<tr valign="top">
												<td width="170">
													<!-- BEGIN subjects -->
														{subj_list}
													<!-- END subjects -->
												</td>
												<td width="10"></td>
												<td>
												
													<input type="hidden" value="{active_subj}" id="active_subj"  />
													<input type="hidden" id="active_subj_irreg"  />
												
													<input type="hidden" name="list_subj_taken" id="list_subj_taken" value=""/>
													<input type="hidden" name="active_subj_taken" id="active_subj_taken" value="{active_subj_taken}"/>
													<input type="hidden" id="sem_linker_id" value="{sem_linker_id}"/>
													
													<input type="hidden" id="sem_taken_active" value="{sem_taken_active}"/>
													<input type="hidden" id="fourth_next_sem" value="{fourth_next_sem}"/>
													
													<input type="hidden" id="sem_taken_id" value="{sem_taken_id}"/>
													<input type="hidden" id="sem_next_taken" value="{sem_next_taken}"/>
													<input type="hidden" id="stud_id" value="{stud_id}"/>
													<input type="hidden" id="course_id" value="{course_id}"/>
													<input type="hidden" id="course_desc" value="{course_desc}"/>
													<input type="hidden" id="sem_desc" value="{sem_desc}"/>
													<input type="hidden" id="redirect" value="{redirect}"/>
											
													<input type="hidden" id="subj_failed" value="{subj_failed}"/>
													
													<input type="hidden" id="inc_taken_subj" value="{inc_taken_subj}"/>
													<input type="hidden" id="is_regular" value="{is_regular}"/>
													
													<div id="enrollment_popup"></div>
													<div class="ajax-enrollment-value" id="enrollment_value_stud_subj"></div>
													
													<div id="stud_grade_subj_enroll_list"></div>
													
												</td>
											</tr>
										</table>
		
									</div>
									<input type="submit" name="subButton" class="enroll-save-button" value="Save" id="save_submit_button"/>
								</form>
							</div>
					</div>
				</td>
			</tr>
		</table>
		
	</div>
<!-- FOOTER -->{page_footer}<!-- FOOTER -->
<script type="text/javascript">

	$(document).ready(function() {
		selectGradeTransfery();
		$('#save_submit_button').hide();
	});
	
	function selectGradeTransfery() {
		var strSemLinker = $('#sem_next_taken').val();
		$.post('request.php', {AJAXPost:'gradeTotalUnitsPerSemester', sem_linker_id:strSemLinker}, function(res) {
			$('#total_units').text(res.total_units);
			regular();
		}, 'json');
	}
	
	function regular() {
		
		var sem_next_taken 	   = $('#sem_next_taken').val();
		var sem_desc 		   = $('#sem_desc').val();
		var enrollment_popup   = $('#enrollment_popup');
		var list_subj_taken	   = $('#list_subj_taken');
		var active_subj_taken  = $('#active_subj_taken');
		var sem_taken_active   = $('#sem_taken_active').val();
		var fourth_next_sem    = $('#fourth_next_sem').val();
		var stud_id    	   	   = $('#stud_id').val();
		var course_id    	   = $('#course_id').val();
		
		var inc_taken_subj     = $('#inc_taken_subj').val();
		var is_regular    	   = $('#is_regular').val();
		
		enrollment_popup.html('');
		list_subj_taken.val('');
		
		
		if ( inc_taken_subj > 0 && is_regular == 'N' ) {
			studentGradeSubjListing($('#stud_id').val(), $('#course_id').val())
			selectGradeTransferyIrreg(sem_desc, sem_next_taken);
		}
		else {
			var sem_enrol_value = '';
			$.post('request.php', {AJAXPost:'InputGradeRequisite', strSubjLinkerID:sem_next_taken, strSemLinkerActiveID:sem_taken_active, stud_id:stud_id, take_course:course_id}, function(res) {
				if (res == 0) {
					enrollment_popup.append('<div class="enrollment-label">' + sem_desc + '</div><div class="ajax-enrollment-value">No Record Found.</div>');
				}
				else {
					
					strArrayActiveSubj = $('#active_subj').val().split('-');
					strArraySubjFailed = $('#subj_failed').val().split('-');
					
					active_subj_taken.val(sem_next_taken);
					
					var value_unit = 0;
					
					$.each(res, function(first_key, first_value) {
						
							getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list');
							
							enrollment_popup.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list' + first_key + '"></div>');
					
							$.each( first_value, function( key, value ) {
								
								sem_enrol_value = sem_enrol_value + value['subj_idPK'] + ',';
								strResultInArray = $.inArray(value['pre_req'], strArrayActiveSubj);
								if(strResultInArray < 0 || value['pre_req'] == '') {
								
									value_unit += parseInt(Math.abs(value.total_units));
									$('#add_units').text(value_unit);
									
									if (list_subj_taken.val() == '')
										list_subj_taken.val(value['subj_idPK']);
									else
										list_subj_taken.val(list_subj_taken.val() + ', ' + value['subj_idPK']);
									
									
									strResultFailedArray = $.inArray(value['subj_idPK'], strArraySubjFailed);
									
									/*if(strResultFailedArray < 0) {*/
										enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="1"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_check.png" onclick="studNewEnrollyValue(\'' + value['subj_idPK'] + '\', \'' + value['subj_idPK'] +'\', \'' + value['total_units'] + '\');" border="0"  class="cursor-pointer"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
									/*}
									else {
										enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="1"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_lock.png" border="0"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
									}*/
									
								}
								else {
									$.post('request.php', {AJAXPost:'InputGradeRequisiteGradeIfDrop', stud_subj_linker_id:value['pre_req'], stud_sem_linker_id:sem_taken_active, stud_id:$('#stud_id').val()}, function(g) {
										if ( g.grade == 'DRP' 	||
											 g.grade == '4' 	||
											 g.grade == '4.0' 	||
											 g.grade == '5'		||
											 g.grade == '5.0' 	||
											 ( g.grade <  '75' && g.grade >  '5' )	) {
											enrollment_popup.append('<div class="enrollment-lock font-grey"><img src="./application/images/icon/checkbox_remove.png" border="0"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
										}
										else {
											enrollment_popup.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="0"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_uncheck.png" border="0" onclick="studNewEnrollyValue(\'' + value['subj_idPK'] + '\', \'' + value['subj_idPK'] +'\', \'' + value['total_units'] +'\');" class="cursor-pointer"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
										}
									}, 'json');
								}
							});
						
						});
						
						if ( parseInt($('#total_units').text()) < value_unit ) {
							$('#units_label').css('color', '#F00')	
							$('#save_submit_button').hide();
						}
						else {
							$('#units_label').css('color', '#00F')
							$('#save_submit_button').show();
						}
								
						if ( fourth_next_sem != '' ) {
							enrollment_popup.append('<div class="regular-add-subj" onclick="getAddSemester(\'' + fourth_next_sem + '\');"><table width="0" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td width="18" height="14"><input type="hidden" id="next_sem_img" value="0"/><img src="./application/images/icon/add.png" border="0" /></td><td class="font-white"><span id="subj_add_label">ADD</span> SUBJECT</td></tr></table></div><div id="fourth_year_sem"><div id="sem_stud_grade_enroll_list_next"></div></div>');
						}
				}
				$('#sem_enrollees_value').val(sem_enrol_value);
				$('#view_enrollment_popup').slideDown();
			}, 'json');
		}
	}
	
	function getAddSemester(strNextSemID) {
		
		if ($('#next_sem_img').val() == 0) {
			var sem_stud_grade_enroll_list_next = $('#sem_stud_grade_enroll_list_next');
			sem_stud_grade_enroll_list_next.html('');
			$.post('request.php', {AJAXPost:'StudentNextSubjectDetails', strSubjLinkerID:strNextSemID}, function(res) {
				
				$.each(res, function(first_key, first_value) {
						
						getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list_next');
						
						sem_stud_grade_enroll_list_next.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list_next' + first_key + '"></div>');
				
						$.each( first_value, function( key, value ) {
							
							sem_stud_grade_enroll_list_next.append('<div class="enrollment-lock"><input type="hidden" id="hidden_subj_id' + value['subj_idPK'] + '" value="0"/><img id="but_subj_id' + value['subj_idPK'] + '" src="./application/images/icon/checkbox_uncheck.png" border="0" onclick="studNewEnrollyValue(\'' + value['subj_idPK'] + '\', \'' + value['subj_idPK'] +'\', \'' + value['total_units'] +'\');" class="cursor-pointer"/> ' + value['subj_desc'] + ' (' + value['subj_code'] +')</div>');
							
						});
						
					});
				$('#subj_add_label').text('HIDE');	
				$('#next_sem_img').val(1);	
			}, 'json');
		}
		else {
			window.location.href = window.location.href;
		}
		
	}
	
	function getStudentSemesterDesc(strSem, strDdivID) {
		$.post('request.php', {AJAXPost:'Semester', sem_id:strSem}, function(res) {
			$('#'+strDdivID+strSem).text(res.sem_desc)
		}, 'json');
	}
		
	function studNewEnrollyValue(strID, strValue, strSubjUnits) {
		var list_subj_taken = $('#list_subj_taken');
		
		var add_units  	 = $('#add_units').text();
		var total_units  = parseInt($('#total_units').text());
		 	
		sum_total_comput_units  = parseInt(add_units) + parseInt(Math.abs(strSubjUnits));
		diff_total_comput_units = parseInt(add_units) - parseInt(Math.abs(strSubjUnits));
		
		if (list_subj_taken.val() == '') 
			list_subj_taken.val(strValue);	// Auto Add Value
		else
			list_subj_taken.val(list_subj_taken.val() + ', ' + strValue);
			
		strArray = list_subj_taken.val().split(', ');
		if ( $('#hidden_subj_id'+strID).val() == 0 ) {
			
			if ( total_units < sum_total_comput_units || sum_total_comput_units == 0 ) {
				$('#units_label').css('color', '#F00')	
				$('#save_submit_button').hide();
			}
			else {
				$('#units_label').css('color', '#00F')
				$('#save_submit_button').show();
			}
			$('#add_units').text(sum_total_comput_units);
			$('#list_subj_taken').val(strArray.join(", "));
			$('#hidden_subj_id'+strID).val(1);
			$('#but_subj_id'+strID).attr('src','./application/images/icon/checkbox_check.png');
		}
		else {
			
			if ( total_units < diff_total_comput_units || diff_total_comput_units == 0) {
				$('#units_label').css('color', '#F00')	
				$('#save_submit_button').hide();
			}
			else {
				$('#units_label').css('color', '#00F')
				$('#save_submit_button').show();
			}
			
			$('#add_units').text(diff_total_comput_units);
			
			arr = $.grep(strArray, function(n, i){ return (n != strValue); });
			list_subj_taken.val(arr.join(", "));
			$('#hidden_subj_id'+strID).val(0);
			$('#but_subj_id'+strID).attr('src','./application/images/icon/checkbox_uncheck.png');
		}
		
	}
	
	
	// Transfery > Compute Total Units Per Semester
	function selectGradeTransferyIrreg(strDesc, strSemLinker) {
		
		$('#active_subj_taken').val(strSemLinker);
		
		var strStudID = $('#stud_id').val();
		var strCourseID = $('#course_id').val();
		$.post('request.php', {AJAXPost:'gradeTotalUnitsPerSemester', sem_linker_id:strSemLinker}, function(res) {
			gradeSubjEnrollListingSubjects(strStudID, strCourseID, strSemLinker);
		}, 'json');
	}
	
		// Transfery > Select Semester > Enroll Subjects
		function gradeSubjEnrollListingSubjects(strStudID, strCourseID, strSemLinker) {
			var stud_grade_subj_enroll_list = $('#stud_grade_subj_enroll_list');
			stud_grade_subj_enroll_list.html('');
			var subj_transfery_first_key = '';
			$.post('request.php', {AJAXPost:'GradeSubjEnrollSemester', stud_id:strStudID, course_id:strCourseID, sem_linker_id:strSemLinker}, function(res) {
				
				$.each(res, function(first_key, first_value) {
					
					getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list');
					subj_transfery_first_key += first_key + ',';
					stud_grade_subj_enroll_list.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list' + first_key + '"></div>');
					stud_grade_subj_enroll_list.append('<table width="0" border="0" cellspacing="0" cellpadding="0">');
					$.each(first_value, function(second_key, second_value) {
						
						stud_grade_subj_enroll_list.append('<tr class="hover-light">'+
																'<td width="15" height="16">'+
																	'<div id="button_enroll_get_data' + second_value['subj_idPK'] + '">'+
																		'<input type="hidden" class="hidden_trans_subj_id" id="hidden_trans_subj_id' + second_value['subj_idPK'] + '" value="0"/>'+
																		'<input type="hidden" id="unit_number' + second_value['subj_idPK']  + '" value="' + Math.abs(second_value['total_units'])  + '">'+
																		'<img id="but_trans_subj_id' + second_value['subj_idPK'] + '" src="{dir_image}icon/checkbox_uncheck.png" border="0" class="but_trans_subj_id cursor-pointer" onclick="studNewTransferyEnrollyValue(\'' + second_value['subj_idPK'] + '\', \'' + second_value['subj_idPK'] +'\', \'' + Math.abs(second_value['total_units'])  + '\');" />'+
																	'<div>'+
																'</td>'+
																'<td width="500">'+
																	'<span class="transfery_desc_code cursor-pointer" id="transfery_desc_code' + second_value['subj_idPK'] + '" onclick="studNewTransferyEnrollyValue(\'' + second_value['subj_idPK'] + '\', \'' + second_value['subj_idPK'] +'\', \'' + Math.abs(second_value['total_units'])  + '\');">' + second_value['subj_desc'] + ' (' + second_value['subj_code'] +')</span>'+
																'</td>'+
																'<td width="100">' + Math.abs(second_value['total_units']) + ' Units</td></tr>');
						
					});
					stud_grade_subj_enroll_list.append('</table>');
				});
				
				getRequisiteData();
				
			}, 'json');
		}
				
			// Transfery > Input Value to Input Text Box
			function studNewTransferyEnrollyValue(strID, strValue, strSubjUnits) {
				
				var subj_units_span  = $('#add_units').text();
				var total_units_span = $('#total_units').text(); 
				
				sum_total_comput_units  = parseInt(subj_units_span) + parseInt(strSubjUnits);
				diff_total_comput_units = parseInt(subj_units_span) - parseInt(strSubjUnits);
				
				var list_subj_taken  = $('#list_subj_taken');
				
				if ( sum_total_comput_units <= total_units_span ) {
					if (list_subj_taken.val() == '') 
						list_subj_taken.val(strValue);	// Auto Add Value
					else
						list_subj_taken.val(list_subj_taken.val() + ', ' + strValue);
				}
				
				strArray = list_subj_taken.val().split(', ');
				
				if ( $('#hidden_trans_subj_id'+strID).val() == 0 ) {
					if ( total_units_span < sum_total_comput_units || sum_total_comput_units == 0 ) {
						$('#units_label').css('color', '#F00')	
						$('#save_submit_button').hide();
					}
					else {
						$('#units_label').css('color', '#00F')
						$('#save_submit_button').show();
					}
					$('#subj_units_span').text(sum_total_comput_units);
					$('#list_subj_taken').val(strArray.join(", "));
					$('#hidden_trans_subj_id'+strID).val(1);
					$('#but_trans_subj_id'+strID).attr('src','{dir_image}icon/checkbox_check.png');
					$('#add_units').text(sum_total_comput_units);
				}
				else {
					if ( total_units_span < diff_total_comput_units || diff_total_comput_units == 0) {
						$('#units_label').css('color', '#F00')	
						$('#save_submit_button').hide();
					}
					else {
						$('#units_label').css('color', '#00F')
						$('#save_submit_button').show();
					}
					arr = $.grep(strArray, function(n, i){ return (n != strValue); });
					list_subj_taken.val(arr.join(", "));
					$('#hidden_trans_subj_id'+strID).val(0);
					$('#but_trans_subj_id'+strID).attr('src','{dir_image}icon/checkbox_uncheck.png');
					$('#subj_units_span').text(diff_total_comput_units);
					$('#add_units').text(diff_total_comput_units);
				}
				
			}
			
			// Transfery > Credit Subject Listing
			function studentGradeSubjListing(strStud, strCourse) {
				$.post('request.php', {AJAXPost:'StudentGradeSubjListing', stud_id:strStud, course_id:strCourse}, function(res) {
					var subj_active_list = '';
					$.each(res, function(first_key, first_value) {
						$.each(first_value, function(second_key, second_value) {
							subj_active_list += second_value['subj_idPK'] + '-';
						});
					});
					$('#active_subj_irreg').val(subj_active_list);
				}, 'json');
			}
		
			function getRequisiteData() {
				$.post('request.php', {AJAXPost:'requisiteSubjCourse', course_id:$('#course_id').val()}, function(res) {
					strArrayActiveSubj = $('#active_subj_irreg').val().split('-');
					$.each(res, function(first_key, first_value) {
						$.each(first_value, function(second_key, second_value) {
							strResultInArray = $.inArray(second_value['pre_req'], strArrayActiveSubj);
							if(strResultInArray < 0 || second_value['pre_req'] == '') {
								$('#button_enroll_get_data'+second_value['subj_idFK']).html('<img src="{dir_image}icon/checkbox_remove.png" border="0" />');
								$('#transfery_desc_code'+second_value['subj_idFK']).attr('onclick', false);
							}
						});
					});
				}, 'json');
			}
	
	
	
</script>
</body>
</html>
